package com.gs.spring.service.impl;

import java.security.MessageDigest;

import org.springframework.security.core.codec.Base64;

import com.gs.spring.domain.Car;
import com.gs.spring.service.PersonService;

public class PersonServiceImpl implements PersonService {
	private Car car;
	private MessageDigest digest1;
	private MessageDigest digest2;
	
	
	public PersonServiceImpl(Car car) {
		this.car = car;
	}
	public Car getCar() {
		return car;
	}
	
	public void setDigest1(MessageDigest digest1) {
		this.digest1 = digest1;
	}
	
	public void setDigest2(MessageDigest diagest2) {
		this.digest2 = diagest2;
	}
	public void digest(String msg) {
		System.out.println("using digest1");
		digest(msg,digest1);
		
		System.out.println("using digest2");
		digest(msg,digest2);		
	}
	
	private void digest(String msg, MessageDigest digest) {
		
		System.out.println("Using algorithm: " + digest.getAlgorithm());
		digest.reset();
		
		byte[] bytes = msg.getBytes();
		byte[] out = digest.digest(bytes);
		
		System.out.println(Base64.encode(out)); 
		
	}
	
}
